/*
 * RectangleObject.cpp  0.4.0 / Nov 17, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#include "RectangleObject.h"

#include "JNISwingWrapper.h"

// RectangleObject :: Public Constructor. --------------------------------------

/*!
 * \brief Constructs new RectangleObject object.
 *
 * \param env the JNIEnv pointer
 * \param obj the Swing Rectangle object
 */
RectangleObject::RectangleObject(JNIEnv *env, jobject obj)
  : GlobalJObject(env, obj)
{
  Q_ASSERT(m_obj);
}

// RectangleObject :: Public Member Functions. ---------------------------------

/*!
 * \brief Returns x coordinate of the rectangle.
 *
 * \param result the result
 *
 * \return \c true if no exception is thrown
 */
bool RectangleObject::getX(jint &result)
{
  return JNIWrapper::callIntMethod(m_env, result, m_obj, sm_getXMID);
}

/*!
 * \brief Returns x coordinate of the rectangle.
 *
 * \param env the JNIEnv pointer
 * \param result the result
 *
 * \return \c true if no exception is thrown
 */
bool RectangleObject::getX(JNIEnv *env, jint &result)
{
  return JNIWrapper::callIntMethod(env, result, m_obj, sm_getXMID);
}

/*!
 * \brief Returns y coordinate of the rectangle.
 *
 * \param result the result
 *
 * \return \c true if no exception is thrown
 */
bool RectangleObject::getY(jint &result)
{
  return JNIWrapper::callIntMethod(m_env, result, m_obj, sm_getYMID);
}

/*!
 * \brief Returns y coordinate of the rectangle.
 *
 * \param env the JNIEnv pointer
 * \param result the result
 *
 * \return \c true if no exception is thrown
 */
bool RectangleObject::getY(JNIEnv *env, jint &result)
{
  return JNIWrapper::callIntMethod(env, result, m_obj, sm_getYMID);
}

/*!
 * \brief Returns width of the rectangle.
 *
 * \param result the result
 *
 * \return \c true if no exception is thrown
 */
bool RectangleObject::getWidth(jint &result)
{
  return JNIWrapper::callIntMethod(m_env, result, m_obj, sm_getWidthMID);
}

/*!
 * \brief Returns width of the rectangle.
 *
 * \param env the JNIEnv pointer
 * \param result the result
 *
 * \return \c true if no exception is thrown
 */
bool RectangleObject::getWidth(JNIEnv *env, jint &result)
{
  return JNIWrapper::callIntMethod(env, result, m_obj, sm_getWidthMID);
}

/*!
 * \brief Returns height of the rectangle.
 *
 * \param result the result
 *
 * \return \c true if no exception is thrown
 */
bool RectangleObject::getHeight(jint &result)
{
  return JNIWrapper::callIntMethod(m_env, result, m_obj, sm_getHeightMID);
}

/*!
 * \brief Returns height of the rectangle.
 *
 * \param env the JNIEnv pointer
 * \param result the result
 *
 * \return \c true if no exception is thrown
 */
bool RectangleObject::getHeight(JNIEnv *env, jint &result)
{
  return JNIWrapper::callIntMethod(env, result, m_obj, sm_getHeightMID);
}

// RectangleObject :: Public Static Member Function. ---------------------------

/*!
 * \brief Initializes RectangleObject class.
 *
 * \param env the JNIEnv pointer
 * \param cls the Swing Rectangle class
 *
 * \exception FatalError if failed
 */
void RectangleObject::initialize(JNIEnv *env, jclass cls)
{
  Q_ASSERT(env);
  Q_ASSERT(cls);
  Q_ASSERT(!sm_rectangleClass);
  if (!INIT_CLASS(rectangle, cls) ||
      !INIT_CONSTRUCTOR(constructor, cls, "(IIII)V") ||
      !INIT_MID(getX, cls, "()I") || !INIT_MID(getY, cls, "()I") ||
      !INIT_MID(getWidth, cls, "()I") ||
      !INIT_MID(getHeight, cls, "()I")) {
    FATAL_LOGGED_ERROR("RectangleObject initialization failed");
  }
}

/*!
 * \brief Creates new Swing rectangle object.
 *
 * \param x the x coordinate of the rectangle
 * \param y the x coordinate of the rectangle
 * \param width the width of the rectangle
 * \param height the height of the rectangle
 * 
 * \return new instance of the Swing rectangle class
 */
jobject RectangleObject::newObject(jint x, jint y, jint width, jint height)
{
  return JNISwingWrapper::newObject(sm_rectangleClass, sm_constructorMID, x, y,
                                    width, height);
}

// RectangleObject :: Private Static Data Members. -----------------------------

jclass RectangleObject::sm_rectangleClass = 0;
jmethodID RectangleObject::sm_constructorMID = 0;
jmethodID RectangleObject::sm_getXMID = 0;
jmethodID RectangleObject::sm_getYMID = 0;
jmethodID RectangleObject::sm_getWidthMID = 0;
jmethodID RectangleObject::sm_getHeightMID = 0;
